using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Xml;

using Gtk;
using Mono.Cecil;
using MonoDevelop.Components.Commands;
using MonoDevelop.Core;
using MonoDevelop.Core.Gui.Dialogs;
using MonoDevelop.Projects;
using MonoDevelop.Projects.CodeGeneration;
using MonoDevelop.Projects.Parser;
using MonoDevelop.Projects.Text;
using MonoDevelop.Ide.Gui;
using MonoDevelop.Ide.Gui.Pads;
using MonoDevelop.Ide.Gui.Content;
using MonoDevelop.Ide.Tasks;


namespace MonoDevelop.SmokeyAddin
{
        
        internal partial class SmokeyAddinConfigPanelWidget : Bin
        {
                
                public SmokeyAddinConfigPanelWidget ()
                {
                        this.Build ();
                        this.LoadSettings ();
                }
                
                private void LoadSettings ()
                {
                        this.excludeNameEnabledCheckBox.Active = SmokeyConfiguration.ExcludeNameEnabled;
                        this.excludedNameEntry.Text = SmokeyConfiguration.ExcludedName;
                        this.UpdateUI ();
                }
                
                private void UpdateUI ()
                {
                        if (this.excludeNameEnabledCheckBox.Active)
                                this.excludedNameEntry.Sensitive = true;
                        else
                                this.excludedNameEntry.Sensitive = false;
                }
                
                private bool Validate ()
                {
                        if (this.excludeNameEnabledCheckBox.Active) {
                                if (this.excludedNameEntry.Text.IndexOfAny (@" .,/<>?`~!@#$%^&*()-=+'"";:\|[]{}".ToCharArray ()) != -1) {
                                        IdeApp.Services.MessageService.ShowErrorFormatted ("Method or type name '{0}' contains illegal character(s).", this.excludedNameEntry.Text);
                                        return false;
                                } else return true;
                        } else return true;
                }
                
                public bool SaveSettings ()
                {
                        if (this.Validate ()) { 
                                SmokeyConfiguration.ExcludeNameEnabled = this.excludeNameEnabledCheckBox.Active;
                                SmokeyConfiguration.ExcludedName = this.excludedNameEntry.Text;
                                SmokeyConfiguration.Save ();
                                return true;
                        } else {
                                return false;
                        }
                }

                protected virtual void OnExcludeNameEnabledCheckBoxClicked (object sender, System.EventArgs e)
                {
                        this.UpdateUI ();
                }
        }
}
